{include file="public/head"/}
<style>
    .layui-form-label {
        width: 130px;
    }

    .layui-input-block {
        margin-left: 160px;
    }

    #imgTable + .layui-table-view tbody > tr > td {
        padding: 0;
    }

    #imgTable + .layui-table-view tbody > tr > td > .layui-table-cell {
        height: 60px;
        line-height: 60px;
    }

    .tdImg {
        height: 30px;
        max-width: none;
        border: none;
        cursor: pointer;
    }

    .layui-table-view {
        margin: 0;
    }

    .layui-input-num {
        width: 100px;
    }

    .layui-input-title {
        width: 400px;
    }

    .layui-treeSelect .ztree li span.button.switch {
        position: relative;
        top: -6px;
    }

    .none {
        display: none;
    }

    #image img {
        max-width: 160px;
        max-height: 124px;
        overflow: hidden;
    }

    .layui-upload-img {
        width: 100%;
        height: 100%;

    }

    .delimages {
        position: relative;
        width: 92px;
        height: 92px;
        margin: 0 10px 10px 0;
        display: inline-block;
    }

    .click_delimages {
        position: absolute;
        bottom: 0;
        width: 100%;
        text-align: center;
        color: #fff;
        background-color: #9e9e9ea1;
        cursor: pointer;
    }

    .spandiv {
        background: #3C8DBC;
        color: #fff !important;
        padding: 9px 13px !important;
        border-radius: 2px;
        cursor: pointer;
    }

    #addformcate {
        background: #3C8DBC;
        color: #fff !important;
        padding: 9px 13px !important;
        border-radius: 2px;
        cursor: pointer;
    }

    #showformat {
        margin-top: 10px;
    }

    .showformatdiv {
        border: 1px solid #eee;
        padding: .5rem .75rem;
        margin-bottom: .5rem;
        border-radius: .15rem;
    }

    .format_title {
        display: inline-block;
        width: 73%;
    }

    .addformatdiv {
        width: 200px;
        display: inline-block;
    }

    .addform {
        float: right;
        background: #3C8DBC;
        color: #fff !important;
        padding: 9px 6px !important;
        border-radius: 2px;
        cursor: pointer;
    }

    .attr-item {
        display: inline-block;
        background: #eee;
        margin-right: 1rem;
        margin-top: .5rem;
    }

    .attr-item .attr-name {
        padding: .15rem .75rem;
        display: inline-block;
    }

    .attr-item .attr-delete {
        padding: .24rem .6rem;
        background: #d4cece;
        color: #fff;
        font-size: 1rem;
        font-weight: bold;
        cursor: pointer;
    }

    .format_all_stock_num, .format_all_price, .format_stock_num, .format_price {
        width: 100px;
        display: inline-block;
    }

    .format_image {
        width: 200px;
        display: inline-block;
    }

    .tablediv {
        border-color: #e6e6e6;
    }

    .tablediv td, .tablediv th {
        padding: .75rem;
    }

    .tag-item {
        display: inline-block;
        background: #eee;
        margin-right: 1rem;
        margin-top: .5rem;
    }

    .tag-item .tag-name {
        padding: .15rem .75rem;
        display: inline-block;
    }

    .tag-item .tag-delete {
        padding: .24rem .6rem;
        background: #d4cece;
        color: #fff;
        font-size: 1rem;
        font-weight: bold;
        cursor: pointer;
    }

    .addtagspan {
        float: right;
        background: #3C8DBC;
        color: #fff !important;
        padding: 9px 6px !important;
        border-radius: 2px;
        cursor: pointer;
    }
</style>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body" pad15>
                    <div class="layui-form" wid100 lay-filter="">
                        <div class="layui-tab">
                            <ul class="layui-tab-title">
                                <li class="layui-this">优惠卷设置</li>
                            </ul>
                            <div class="layui-tab-content">
                                <div class="layui-tab-item layui-show">


                                    <div class="layui-form-item">
                                        <div class="layui-inline">
                                            <label class="layui-form-label">优惠卷名称</label>
                                            <div class="layui-input-inline">
                                                <input type="text" name="title" lay-verify="required" value="{$info.title|default=''}" placeholder="优惠卷名称" class="layui-input">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <div class="layui-inline">
                                            <label class="layui-form-label">优惠卷说明</label>
                                            <div class="layui-input-inline">
                                                <input type="text" name="desc" lay-verify="required" value="{$info.desc|default=''}" placeholder="优惠卷说明" class="layui-input">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <div class="layui-inline">
                                            <label class="layui-form-label">优惠金额</label>
                                            <div class="layui-input-inline">
                                                <input type="text" name="coupon_price" lay-verify="required" value="{$info.coupon_price|default=''}" placeholder="优惠金额" class="layui-input">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <input type="hidden" name="id" value="{$info.id|default=''}">
                                <button class="layui-btn" lay-submit lay-filter="edit-but">确认保存</button>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>

{include file="public/foot"/}

<script>
    layui.config({
        base: '__LAYDMIN__/',{if config('app.app_debug')}version: true{/if}
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','form','admin','table','colorpicker','upload'],function(){
			var $ = layui.$, admin = layui.admin, table = layui.table, element = layui.element, form = layui.form,util = layui.util, upload = layui.upload,colorpicker = layui.colorpicker;
			//编辑提交
			var uri="{if isset($info['id'])}{:url(SYS_PATH.'/'.CONTROLLER.'/edit')}{else}{:url(SYS_PATH.'/'.CONTROLLER.'/add')}{/if}";
			form.on('submit(edit-but)', function (data) {
				admin.req({
					url: uri //实际使用请改成服务端真实接口
					, type: 'post'
					, data: data.field
					, done: function (res) {
						window.top.layer.msg(res.msg, {icon: 1, time: 1000,shade:[0.5,'#000']}, function () {
							layer.closeAll("iframe");
							//刷新父页面
							parent.location.reload();
						});
					}
				});
			});

		//上传logo
		var thumb = $('#cover');
		upload.render({
			url: '{:url(SYS_PATH."/uploads/upimg")}'
			, elem: '#thumbUpload'
			, done: function (res) {
				if (res.code == 0) {
					thumb.val(res.url);
					//logo.parent().append('<input type="hidden" name="logo_aid" value="'+res.aid+'">')
				} else {
					layer.msg(res.msg, {icon: 5});
				}
			}
		});
		//查看logo
		admin.events.logoShow = function (othis) {
			var src = thumb.val();
			layer.photos({
				photos: {
					"title": "查看图片" //相册标题
					, "data": [{
						"src": src //原图地址
					}]
				}
				, shade: 0.01
				, closeBtn: 1
				, anim: 5
			});
		};


        // 获取多图
        {if isset($info['id'])}
            $(function() {
                var id = {$id};
                var url = "{:url(SYS_PATH.'/Goods/getImages')}";
                $.ajax({
                    url:url,
                    type:'get',
                    data:{id:id},
                    success:function(req){
                        var list = JSON.parse(req); //返回的数据
                        for (var p in list) {
                            $('#imagesshow').append('' +
                                '<div class="delimages">' +
                                '<input name="images[]" type="hidden" value="' + list[p] + '">' +
                                '<img src="' + list[p] + '" alt="' + list[p] + '" class="layui-upload-img">' +
                                '<div class="click_delimages">点击删除</div>' +
                                '</div>');
                        }
                    }
                });
            });
        {/if}


        //多图片上传
        upload.render({
            url: '{:url(SYS_PATH."/uploads/upimg")}',
            elem: '#images',
            multiple:true,
            done: function (res) {
                console.log(res);
                //上传完毕
                $('#imagesshow').append('<div class="delimages"><input name="images[]" type="hidden" value="' + res.url + '"><img src="' + res.url + '" alt="' + res.url + '" class="layui-upload-img"><div class="click_delimages">点击删除</div></div>');

            }
        });

        $(document).off("click", ".click_delimages");
        $(document).on('click', '.click_delimages', function () {
            $(this).parent().remove();
        });
	});
</script>
</body>
</html>